package de.tabuma.sso.attribute;

import java.util.*;
import de.tabuma.sso.*;
import de.tabuma.sso.sso.*;
import de.tabuma.sso.group.*;
import de.tabuma.sso.usergroup.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.2.1 $
 * @since $Date: 2010/01/08 10:03:24 $
 */
public class AttributeWebserviceLib {
    public static void userHasPrivileg(String ssoId) throws Exception {
        if(SSOFacade.sessionIsActiv(ssoId)) {
            if(SSOFacade.userHasAdminUserPrivileg(ssoId)!=-1) {
                return;
            }
        }
        throw new Exception("User has no privileg to do something with attributes.");
    }

    public static int getLicenseGroup(String ssoId) {
        SSO sso = SSOFacade.get(ssoId);
        List<UserGroup> ugList = UserGroupFacade.getList1(sso.getUserId());
        for(int i=0;i<ugList.size();i++) {
            Group g = GroupFacade.get(ugList.get(i).getGroupId());
            if(g.getNoLicenseNeeded().booleanValue()) {
                return 0;
            }
        }
        if(ugList.size()>0) {
            return ugList.get(0).getGroupId();
        }
        return 0;
    }
}